/*
 * @Author: your name
 * @Date: 2021-12-27 12:12:35
 * @LastEditTime: 2021-12-27 21:07:28
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue\vue-douban-pc\src\utils\auth.js
 */
import { Session } from "./index";

const TOKEN_KEY = "MY-TOKEN";
const USERINFO_KEY = "MY-USERINFO";

//token相关方法
export function getToken() {
    return Session.get(TOKEN_KEY);
}

export function setToken(token) {
    Session.set(TOKEN_KEY, token);
}

export function removeToken() {
    Session.remove(TOKEN_KEY);
}

//userinfo相关方法
export function getUserInfo() {
    return Session.get(USERINFO_KEY);
}

export function setUserInfo(userInfo) {
    Session.set(USERINFO_KEY, userInfo);
}

export function removeUserInfo() {
    Session.remove(USERINFO_KEY);
}

//Cookie相关方法
export function setCookie(name, value, iDay) {
    let oDate = new Date();
    oDate.setDate(oDate.getDate() + iDay);
    document.cookie = name + '=' + value + ';expires=' + oDate;
}

export function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if (cookieName == arr[0]) {
            return arr[1];
        }
    }
    return "";
}

export function removeCookie(name) {
    setCookie(name, 1, -1);
}